<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box1{
            margin: 50px;
            width: 50px;
            height: 50px;   
            background-color: pink;
        }
        .box{
            margin: 20px;
            width: 220px;
            height: 220px;
            background-color: springgreen;
            position: relative;
            padding: 20px;
            /* 外边距塌陷 */
            /* BFC */
            overflow: hidden;
        }
        body{
            width: 3000px;
            height: 3000px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="box1"></div>
    </div>
    <script>    
        var div = document.querySelector(".box1")
        /* 
            offsetTop
            offsetLeft
                如果有父级有定位(静态定位,固定定位,相对定位,那么参数物父元素)
                如果父级没有定位,那么参照物是浏览器的第一屏
                当浏览器的滚动条发送滑动的时候,参照物还是第一屏
        */
       console.log(div.offsetTop,div.offsetLeft);
    </script>
</body>
</html>